<!DOCTYPE html>
<html lang="en">
<body>
<div id="msg"></div>
<input type="text" id="text">
<input type="submit" value="send" onclick="send()">
</body>
</html>
<script type="text/javascript" src="/js/websocket.js"></script>
<script type="text/javascript">
    var websocket=connectionWebSocket();
    var msg = document.getElementById("msg");
    //监听服务器数据推送
    websocket.onmessage = function (evt) {
        msg.innerHTML += "<br>" + evt.data;
    };
    function connectionWebSocket() {
        var wsServer = 'ws://localhost:80';
        var websocket = new WebSocket(wsServer);
        //监听连接打开
        websocket.onopen = function (evt) {
            console.log("Netty 链接成功")
            websocket.send("链接测试")
        };
        //监听连接关闭
        websocket.onclose = function (evt) {
            alert("连接关闭");
        };
        return websocket;
    }</script>
